<?php
class Liste
{
	
	public $table;
	public $table_principale;
	public $cle;
	
	public function Liste($tp,$tab,$c){
		
		$this->table_principale= $tp;
		$this->table = $tab;
		$this->cle=$c;
	}
	
	public function getTable(){
		
			require_once("../test/php_connect.php");
			$connexion = new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
			$sql="SELECT * FROM ".$this->table_principale;
			foreach($this->table as $key => $tab)
					if(sizeof($tab)==1)
						$sql = $sql." INNER JOIN ".$tab[0]." ON ".$this->table_principale.".".$key."=".$tab[0].".".$key;
					else
						$sql = $sql." INNER JOIN ".$tab[1]." ON ".$tab[0].".".$key."=".$tab[1].".".$key;
			$regexp = "/id/";
			$query = $connexion->query($sql);
			$tab_resul = array();
			$nb_col = $query->columnCount();
			echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"display\" id=\"table_recherche\">
				<thead>
					<tr>";
						for ($i=0; $i<$nb_col; $i++){
							$meta = $query->getColumnMeta($i); 
							if(!preg_match($regexp,$meta['name']))
								echo '<th>'.$meta['name'].'</th>';
						}
					echo " </tr>
				</thead>
				<tbody>";
				foreach($query as $row){
					echo "<tr class='gradeA' id='".$row[$this->cle]."'>";
					for ($i=0; $i<$nb_col; $i++){
							$meta = $query->getColumnMeta($i); 
							if(!preg_match($regexp,$meta['name']))
								echo "<td>". $row[$meta['name']]."</td>";
						}
					echo "</tr>";
				}	
				echo "</tbody>
				<tfoot>
					<tr>";
						for ($i=0; $i<$nb_col; $i++){
							$meta = $query->getColumnMeta($i); 
							if(!preg_match($regexp,$meta['name']))
								echo "<th><input type=\"text\" name=\"search_".$meta['name']."\" value=\"Recherche\" class=\"search_init\" /></th>";
						}
					echo "</tr>
				</tfoot>
			</table>";
	}
}